<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>资料上传</title>
<!-- <link rel="stylesheet" type="text/css" href="${base}/css/system/bootstrap/bootstrap.min.css"/> -->
<link rel="stylesheet" href="${base}/css/system/bootstrap/fileinput/fileinput.css" />
<script type="text/javascript" src="${base}/js/system/jquery.min.js"></script>
<script type="text/javascript" src="${base}/js/system/layer/layer.js"></script>
<script type="text/javascript" src="${base}/js/system/bootstrap/bootstrap.min.js"></script>
<script type="text/javascript" src="${base}/js/system/bootstrap/fileinput/fileinput.js"></script>
<script type="text/javascript" src="${base}/js/system/bootstrap/fileinput/zh.js"></script>
<script type="text/javascript" src="${base}/js/system/jquery.serializejson.js"></script>
</head>
<body>
<div class="container-fluid">
    <form id="form" action="" method="post" enctype="application/x-www-form-urlencoded">
      <input type="hidden" name="gs" value="${isEmpty(obj.data)?'':obj.data.gs}">
      <input type="hidden" name="sms" value="${isEmpty(obj.data)?'':obj.data.sms}">
      <input type="hidden" name="dtt" value="${isEmpty(obj.data)?'':obj.data.dtt}">
      <input type="hidden" name="zpmbzt" value="${isEmpty(obj.data)?'':obj.data.zpmbzt}">
      <input type="hidden" name="id" value="${isEmpty(obj.data)?'':obj.data.id}"> 
      <div class="row form-group">
         <div class="panel-primary">
           <div class="panel-heading" align="center">
             <label style="text-align: center;font-size: 18px;">动车设施数据库资料上传</label>
           </div>
           
         <div class="panel-body">
         <label class="col-sm-2 control-label">总平面布置图上传:</label>
           <div class="col-sm-10">
              <input id="zpmbzt" name="file" multiple type="file" data-show-caption="true">
           </div>
         </div>
         
         <div class="panel-body">
         <label class="col-sm-2 control-label">单体图上传:</label>
           <div class="col-sm-10">
              <input id="dtt" name="file" multiple type="file" data-show-caption="true">
           </div>
         </div>
         

         <div class="panel-body">
         <label class="col-sm-2 control-label">说明书上传:</label>
           <div class="col-sm-10">
              <input id="sms" name="file" multiple type="file" data-show-caption="true">
           </div>
         </div>

         <div class="panel-body">
         <label class="col-sm-2 control-label">概算文件上传:</label>
           <div class="col-sm-10">
              <input id="gs" name="file" multiple type="file" data-show-caption="true">
           </div>
         </div>
        
        </div>
      </div>
    </form>
</div>
<script type="text/javascript">
	$(function () {
	    var ctrlName_strs = "zpmbzt,dtt,sms,gs"; 
		ctrlName_str = ctrlName_strs.split(",");
		for(var i=0;i<ctrlName_str.length;i++){
			var control = $('#' + ctrlName_str[i]);
			var suffix_name = [];
			if("zpmbzt" == ctrlName_str[i] || "dtt" == ctrlName_str[i]){
				suffix_name = ['dwg'];
			}else if("gs" == ctrlName_str[i]){
				suffix_name = ['xls','xlsx'];
			}else{
				suffix_name = ['doc','docx','jpg','png','gif'];
			}
			var initialPreview = [];//图片路径
			var initialPreviewConfig = [];//图片概况
			//初始化缩略图
			var file_id = $("input[name='"+ctrlName_str[i]+"']").val();
			if(file_id != ""){
				var file_array = file_id.split(",");
				for(var j=0;j<file_array.length;j++){
				    $.ajax({
				        url: "${base}/datacenter/common/findFileInfoById/"+file_array[j]+"/"+ctrlName_str[i],
				        data: {},
				        async:false,
				        success: function (data, textStatus, jqXHR) {
				        	var key = data.key;
				        	var caption = data.caption;
				        	var url = data.url;
				        	initialPreview.push("${base}/datacenter/common/getFileById?file_id="+key);
				        	initialPreviewConfig.push({caption:caption,url:url});
				        },
				        error: function () {
				        }
				    });
				}
			}
		    control.fileinput({
		        language: 'zh', //设置语言
		        uploadUrl: "${base}/datacenter/common/multifileUploadFile?file_kind=equipment&field_name="+ctrlName_str[i], //上传的地址
		        allowedFileExtensions: suffix_name,//接收的文件后缀
		        maxFilesNum : 5,//上传最大的文件数量
		        uploadAsync: true, //默认异步上传
		        layoutTemplates :{
		            actionDelete:'', //去除上传预览的缩略图中的删除图标
		            actionUpload:'',//去除上传预览缩略图中的上传图片；
		            actionZoom:''   //去除上传预览缩略图中的查看详情预览的缩略图标。
		        },
		        showUpload: true, //是否显示上传按钮
		        showRemove : false, //显示移除按钮
		        showPreview : true, //是否显示预览
		        showCaption: false,//是否显示标题
		        browseClass: "btn btn-primary", //按钮样式
		        dropZoneEnabled: true,//是否显示拖拽区域
		        maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小
		        minFileCount: 0,
		        maxFileCount: 10, //表示允许同时上传的最大文件个数
		        enctype: 'multipart/form-data',
		        validateInitialCount:true,
		        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
		        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
		        initialPreviewAsData:true,
		        initialPreview:initialPreview,//显示图片的途径
		        initialPreviewConfig:initialPreviewConfig 
		    })/* .on('filepreupload', function(event, data, previewId, index) {     //上传中
		        var form = data.form, files = data.files, extra = data.extra,
		        response = data.response, reader = data.reader;
		    }) */.on("fileuploaded", function (event, data, previewId, index) {    //一个文件上传成功
	   	        var file_ids = data.response.data;
		        var field_name = data.response.field_name;
		        $("input[name='"+field_name+"']").val(file_ids);
		    }).on('fileerror', function(event, data, msg) {  //一个文件上传失败
		        console.log('文件上传失败！'+data.id);
		    }).on('filepreremove', function(event, key, jqXHR, data) {
	   	        var file_ids = data.response.data;
		        var field_name = data.response.field_name;
		        $("input[name='"+field_name+"']").val(file_ids);
	         })
		}
	})
/* $("button").click(function(){
 	var data_arr = $('form').serializeArray();
 	var data_json = {};
 	$.each(data_arr,function(index,value){
 		var field_name = value.name;
 		var field_value = value.value;
 		data_json[field_name] = field_value;
 	});
	$.post("${base}/dataCenter/businessdata/updateEquipmentInfo",data_json,
			function (data,status){
			if(data!=""&&data!=null){
				if(data.statusCode == 0){
					layer.msg('更新成功', {icon: 1,time:2000});
				}else{
					layer.msg(data.message, {icon: 2,time:2000});
				}
			}else{
				layer.msg('更新失败!', {icon: 2,time:2000});
			}
	});
	
}); */

</script>
</body>
</html>